<template>
  <div class="app-container">
    <el-form :inline="true" label-width="100px">
      <el-form-item label="供应商编号">
        <el-input
          v-model.trim="queryParams.providerNum"
          placeholder="请输入供应商编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商名称">
        <el-input
          v-model.trim="queryParams.providerName"
          placeholder="请输入供应商名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item>
        <el-button
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          v-hasPermi="['purchase:provider:query']"
        >搜索
        </el-button>
        <el-button
          class="filter-item"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['purchase:provider:add']"
        >新增
        </el-button>
      </el-form-item>
    </el-form>

    <!--供应商详情表-->
    <el-table
      v-loading="loading"
      :data="providerApproveList"
    >
      <el-table-column align="center" label="序号" width="50">
        <template slot-scope="scope">
          {{scope.$index+1}}
        </template>
      </el-table-column>
      <el-table-column label="任务id" align="center" prop="id" sortable="custom" width="150px"/>
      <el-table-column label="任务名称" align="center" prop="name"/>
      <el-table-column label="办理人" align="center" prop="assignee"/>
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="250px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    <el-drawer
      title="供应商审批"
      :visible.sync="drawer"
      :direction="direction"
      :show-close="false"

      size="800px"
      :before-close="handleClose">

      <el-form ref="provider" :model="provider" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="供应商编号" prop="providerNum">
              <el-input v-model.trim="provider.providerNum" placeholder="供应商编号" maxlength="200" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供应商名称" prop="providerName">
              <el-input v-model.trim="provider.providerName" placeholder="请输入供应商名称" maxlength="200" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供应商类型" prop="providerType">
              <el-input v-model.trim="provider.providerType" placeholder="请选择供应商类型" maxlength="100" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="有效期" prop="validDate">
              <el-date-picker
                v-model="provider.validDate"
                type="date"
                placeholder="选择有效期"
                disabled>
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="联系人">
              <el-table
                :data="provider.contactList"
                height="180px"
                border
              >
                <el-table-column label="联系人姓名" align="center">
                  <template slot-scope="scope">
                    <el-input v-model.trim="scope.row.contactName" disabled></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="联系人职位" align="center">
                  <template slot-scope="scope">
                    <el-input v-model.trim="scope.row.contactPos" disabled></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="联系电话" align="center">
                  <template slot-scope="scope">
                    <el-tooltip class="item" effect="dark" :manual="true" content="请输入正确的手机号" v-model="disabled"
                                placement="right">
                      <el-input v-model.trim="scope.row.contactPhone" @blur="checkPhone(scope.row)"
                                maxlength="11" disabled></el-input>
                    </el-tooltip>
                  </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click="handleDeleteContact(scope.$index)"
                      v-hasPermi="['system:post:remove']"
                    >删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注">
              <el-input v-model="provider.remark" type="textarea" placeholder="请输入内容" maxlength="250"
                        disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="审批意见">
              <el-input v-model="provider.remark" type="textarea" placeholder="请输入内容" maxlength="250"
                        clearable></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item>
              <el-button type="primary" @click="submitForm">同 意</el-button>
              <el-button type="warning" @click="submitForm">不同意</el-button>
              <el-button @click="cancel">取 消</el-button>
            </el-form-item>
          </el-col>

        </el-row>

      </el-form>


    </el-drawer>


  </div>
</template>
<script>
  import {getProviderApproveList, getProviderByTaskId} from '@/api/purchase/provider'

  export default {
    name: "providerapprove",
    data() {
      return {
        loading: false,
        total: 0,

        dateRange: undefined,

        queryParams: {
          pageNum: 1,
          pageSize: 10,
          providerNum: "",
          providerName: "",
        },

        providerApproveList: [],


        //审批弹框
        drawer: false,
        provider: {}

      }
    },

    methods: {
      getList() {
        this.loading = true;
        getProviderApproveList(this.queryParams).then(res => {
          this.providerApproveList = res.data;
          this.loading = false;
        }).catch(error => {
          console.log(error);
        })
      },

      //查询
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },

      //查看
      handleUpdate(row) {
        this.drawer = true;
        getProviderByTaskId(row.id).then(res => {
          this.provider = res.data;
        }).catch(err => {
          console.log(err);
        })
      },

      cancel() {
        this.drawer = false;
      }

    },

    created() {
      this.getList();
    }
  }
</script>

<style scoped>
  /deep/ :focus {
    outline: 0;
  }
</style>
